﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace olierFrm.DataBase
{
    public class ConnectionConfig
    {
        public static string FrmDataSource { get; private set; }
        public static string FrmUID { get; private set; }
        public static string FrmPWD { get; private set; }
        public static string FrmDatabase { get; private set; }
        public static string StaDataSource { get; private set; }
        public static string StaUID { get; private set; }
        public static string StaPWD { get; private set; }
        public static string StaDatabase { get; private set; }


        public ConnectionConfig()
        {
            FrmDataSource = ConfigurationManager.AppSettings["FrmDataSource"];
            FrmUID = ConfigurationManager.AppSettings["FrmUID"];
            FrmPWD = ConfigurationManager.AppSettings["FrmPWD"];
            FrmDatabase = ConfigurationManager.AppSettings["FrmDatabase"];
            StaDataSource = ConfigurationManager.AppSettings["StaDataSource"];
            StaUID = ConfigurationManager.AppSettings["StaUID"];
            StaPWD = ConfigurationManager.AppSettings["StaPWD"];
            StaDatabase = ConfigurationManager.AppSettings["StaDatabase"];

            StaEntityConnectionStr = FrmEntityConnectionStr = string.Format(FrmEntityTemplate, FrmDataSource, FrmUID, FrmPWD, FrmDatabase);
            //StaEntityConnectionStr = string.Format(StaEntityTemplate, StaDataSource, StaUID, StaPWD, StaDatabase);
            FrmConnectionStr = string.Format(ConnectionTemplate, FrmDataSource, FrmUID, FrmPWD, FrmDatabase);
            StaConnectionStr = string.Format(ConnectionTemplate, StaDataSource, StaUID, StaPWD, StaDatabase);
        }

        public static string FrmEntityConnectionStr { get; private set; }
        public static string StaEntityConnectionStr { get; private set; }
        public static string FrmConnectionStr { get; private set; }
        public static string StaConnectionStr { get; private set; }

        public const string StaEntityTemplate = "metadata=res://*/FrameWork.StaDBEntity.csdl|res://*/FrameWork.StaDBEntity.ssdl|res://*/FrameWork.StaDBEntity.msl;provider=System.Data.SqlClient;provider connection string=\"Data Source={0};Initial Catalog={3};User ID={1};Password={2};MultipleActiveResultSets=True\"";
        public const string FrmEntityTemplate = "metadata=res://*/FrameWork.FrameWorkEntity.csdl|res://*/FrameWork.FrameWorkEntity.ssdl|res://*/FrameWork.FrameWorkEntity.msl;provider=System.Data.SqlClient;provider connection string=\"Data Source={0};Initial Catalog={3};Persist Security Info=True;User ID={1};Password={2};MultipleActiveResultSets=True\"";
        public const string ConnectionTemplate = "data source={0};UID={1};pwd={2};database={3};Max Pool Size=100;Min Pool Size=0";

    }
}
